package org.jeecg.modules.fund.util;

import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;

import java.util.List;

public class FundAllCodeUtil {
    /**
     * 获取所有的基金代码
     */
    public static JSONArray getAllFund(){
        try {
            String res = HttpRequest
                    .get("https://fund.eastmoney.com/js/fundcode_search.js")
                    .execute()
                    .body();
            // 数据截取
            String result = res.substring(8);
            // 数据格式转换
            JSONArray jsonArray = JSONArray.parseArray(result.replace(";",""));
            return jsonArray;
        } catch (HttpException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args){
        JSONArray res = getAllFund();
        for (int i = 0;i< res.size() && i < 5;i++){
            JSONArray arr = res.getJSONArray(i);
            System.out.println(arr);
        }
    }
}
